package com.ihai.spring.boot.sample.distributed.counter.remote;

import java.util.List;

/**
 * DESC
 *
 * @author 张驰
 * @date 2019/12/23
 */
public class MasterSelector {
    public static Node selectMaster(List<Node> nodeList){
        Node master = null;
        for(Node node : nodeList){
            if(master == null){
                master = node;
            }else{
                int m = (master.getIp() + master.getPort()).hashCode();
                int n = (node.getIp() + node.getPort()).hashCode();
                if(n == Integer.max(m,n)){
                    master = node;
                }
            }
        }
        return master;
    }
}
